--local watch = require "demo.consul.ConsulUtil"
--local broker_watch = watch:new(
--        "http://192.168.212.74:8500/v1/kv/config/smarthome/smarthome-es-srv/smarthome-es-srv.yml",
--        function(co, k)
--            ngx.log(ngx.ERR, "===========>callback key:", k[1]["Key"])
--        end
--)
--
--
--print("准备开始观察") --- - 准备开始
-----
--broker_watch:start()
print("准备开始观察") --- - 准备开始
local ConsulUtil = require "demo.consul.ConsulUtil"
--
--local properties = ConsulUtil.get_Config_from_consul("192.168.1.126",80,
--        "gcd/gcd-bridge-provider/gcd-bridge-provider-dev.properties",
--"data-center-1")
--
--for i,v in pairs(properties) do
--  print("key:" ..i.." value: ".. v)
--end
--

--http://192.168.1.126/v1/kv/config/smarthome/smarthome-es-srv/smarthome-es-srv.yml?dc=data-center-1
--http://192.168.1.126/v1/kv/config/smarthome/smarthome-es-srv/smarthome-se-srv.yml?dc=data-center-1

--- http://www.36nu.com/post/260
---通过调用HTTP API注册服务
---

--curl -X PUT -d '{"service": {"id": "server1","name": "webapi","address": "192.168.1.126", "tags": [ "webapi"], "port": 80}}' http://127.0.0.1:8500/v1/agent/service/register
--print("开始注册")
--local map ={id="server1",name="webapi",address="127.0.0.1",port=80}
ConsulUtil.registerServer("192.168.212.74",8500,"apiservice6","apiservice6","172.200.96.106",80,"http://172.200.96.106:80/health");

--- 步骤 通过 serviceName 去consul 查找ip 端口
--- 将ip端口 和 service name 放入到的内存中， haihaihou
---  配置长链接保证ip 地址 发生变化时候 能第一时间知道
---- 配置upstream
---- 开始负载均衡器
---- 模拟请求 比如 https://127.0.0.1/smarthome-app-srv/sys_auth_login
---- 他会吧请求赚到 在consul 上注册的
local upstream = ConsulUtil.getServiceNodes("192.168.212.74",8500,"apiservice6");
ip_ports= {};
for i,v in pairs(upstream) do
    ip_ports = print("获取到的节点信息为:"..i..v.ip .." port: "..v.port)
end



